<?php
global_config::get_instance()->add_server_class("ArrayOfSoapDimension","soap_array_of_dimension");
require_once(dirname(__FILE__)."/soap_array_base.class.php");
class soap_array_of_dimension extends soap_array_base
{
	public $SoapDimension = array();

	public  function add($item)
	{
		parent::add($this->SoapDimension, $item);
	}

	public function load_from_db($chain_id)
	{

		$dba = db_adapter::get_instance();
		$chain_dimension_composition = new  chain_dimension_composition();
		$criteria = new query_criteria();
		$criteria->add_criterion_composite($chain_dimension_composition->chain_dimension,$chain_dimension_composition->chain_dimension->chain_id,criterion_type::$equal,$chain_id);

		$chain_dimension_composition_list = $dba->get_composite_list($chain_dimension_composition,$criteria);

		while ($dimension = $chain_dimension_composition_list->get_next(false, true))
		{
			$temp  = new soap_dimension();
			$temp->Max = $dimension->dimension->dimension_max->get_value();
			$temp->Min = $dimension->dimension->dimension_min->get_value();
			$this->add($temp);
		}
	}

	public function as_array()
	{
		return parent::to_array($this->SoapDimension);
	}

	/**
	 * Save to db
	 *
	 * @param int $chain_id
	 */
	public function save_to_db($chain_id)
	{
		$dba =db_adapter::get_instance();
		foreach($this->as_array() as $element){
			$dimension_id = $element->save_to_db();
			$chain_dimension = new chain_dimension();
			$chain_dimension->dimension_id->set_value($dimension_id);
			$chain_dimension->chain_id->set_value($chain_id); 
			$dba->save_unique($chain_dimension);
		}
	}
}
?>
